//
//  MKPersonViewController.m
//  ManKeCartoon
//
//  Created by dllo on 15/10/20.
//  Copyright © 2015年 ManKe. All rights reserved.
//

#import "MKPersonViewController.h"
#import "MKBaseHeader.h"
@interface MKPersonViewController ()<UITableViewDataSource, UITableViewDelegate>

@end

@implementation MKPersonViewController
- (void)viewWillAppear:(BOOL)animated {
    
    self.tabBarController.tabBar.hidden = YES;
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view setBackgroundColor:[UIColor whiteColor]];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2-100, 24, 200, 30)];
    
    [self.navBarView addSubview:titleLabel];
    
    [titleLabel setText:self.titleName];
    [titleLabel setTextAlignment:NSTextAlignmentCenter];
    
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [backButton setFrame:CGRectMake(10, 24, 30, 30)];
    //[backButton setBackgroundColor:[UIColor redColor]];
    [self.navBarView addSubview:backButton];
    [backButton addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    [backButton setImage:[UIImage imageNamed:@"iconfont-arrowleft.png"] forState:UIControlStateNormal];
    
    
#pragma mark - 引入页面数据
    [AFNETWORK getDataWithNoCacheString:self.classify_id block:^(id block) {
        
        _mutableArray = [[NSMutableArray alloc] init];
        
        // 遍历  KVC 赋值
        for (NSDictionary *dic in [block objectForKey:@"data"]) {
            MKCRModel *model = [[MKCRModel alloc ] initWithDictionary:dic];
            
            [_mutableArray addObject:model];
            
        }
        
        [self createTableView];
        
    }];
}

#pragma mark - 在navigation上铺个返回键
-(void)BackClick
{
    
    [self.navigationController popViewControllerAnimated:NO];
    
}

#pragma mark - 整个页面的大tableview

- (void)createTableView
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:UITableViewStylePlain];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.scrollsToTop = YES;
    self.tableView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:self.tableView];
}
#pragma mark TableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _mutableArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return SCREEN_HEIGHT / 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"cell";
    MKPersonTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[MKPersonTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
    }
    
    MKCRModel *model = _mutableArray[indexPath.row];
    
    [cell.FLimageView setFrame:CGRectMake(10, 10, SCREEN_WIDTH / 5, SCREEN_HEIGHT / 5 - 20)];
    [cell.FLimageView sd_setImageWithURL:[NSURL URLWithString:model.cover_url]];
    
    [cell.title setFrame:CGRectMake(15 + cell.FLimageView.frame.size.width, cell.FLimageView.frame.origin.y, SCREEN_WIDTH - cell.FLimageView.frame.size.width - 20, cell.FLimageView.frame.size.height / 5)];
    [cell.title setText:model.title];
    
    [cell.lastup setFrame:CGRectMake(cell.title.frame.origin.x, cell.title.frame.origin.y + cell.title.frame.size.height + 10, cell.title.frame.size.width, cell.FLimageView.frame.size.height / 6)];
    [cell.lastup setText:[NSString stringWithFormat:@"更新至%@",model.lastup]];
    
    [cell.type setFrame:CGRectMake(cell.title.frame.origin.x, cell.lastup.frame.size.height + cell.lastup.frame.origin.y + 10, cell.lastup.frame.size.width, cell.lastup.frame.size.height)];
    [cell.type setText:model.type];
    
    [cell.brief_intrd setFrame:CGRectMake(cell.title.frame.origin.x, cell.type.frame.size.height + cell.type.frame.origin.y + 10, cell.lastup.frame.size.width - 10, cell.lastup.frame.size.height)];
    [cell.brief_intrd setText:model.brief_intrd];
    
    
    return cell;
}



#pragma mark - 点击进入对应的漫画页面
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    MKCartoonViewController *cartoon = [[MKCartoonViewController alloc] init];
    MKFLModel *model = _mutableArray[indexPath.row];
    cartoon.comic_id = model.comic_id;
    cartoon.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:cartoon animated:NO];

}

- (void)backClick{
    
    [self.navigationController popViewControllerAnimated:YES];

}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
